document.write('<link type="text/css" rel="stylesheet" href="' + context
		+ '/system/group/css/groupmanage.css"/>');

var root;
// var gdGroupId = 'VmNcsmCnbzYOZqhLIJWD';

/**
 * 初始化
 */
function init() {
	root = groupId;

	var viewport = new Ext.Viewport({
		layout : 'fit',
		items : [new Ext.Panel({
			split : true,
			width : 220,
			autoScroll : false,
			layout : 'border',
			collapsible : false,
			border : false,
			layoutConfig : {
				titleCollapse : true,
				animate : true,
				activeOnTop : false
			},

			items : [new Ext.tree.TreePanel({
				region : 'west',
				id : 'treePanel',
				title : '监理单位',
				split : true,
				width : 350,
				minSize : 250,
				maxSize : 350,
				collapsible : true,
				layout : 'fit',
				border : false,
				layoutConfig : {
					animate : true
				},
				frame : false,
				checkModel : 'single',
				// onlyLeafCheckable : true,
				autoScroll : true,
				animate : true,
				rootVisible : false,
				loader : new Ext.tree.TreeLoader({
					dataUrl : context
							+ '/system/group/groupmapscript.jsp?type=NOROOT_GROUP'
							+ ((root && root != '') ? '&id=' + root : '')
				}),
				root : new Ext.tree.AsyncTreeNode({
							allowChildren : true,
							expanded : true,
							text : 'root', // 节点名称
							draggable : false, // 是否支持拖动
							id : '-1'
						}),
				listeners : {
					'click' : function(node) {
						/*
						 * if (node.isExpanded()) { node.collapse(); } else {
						 * node.expand(); }
						 */

						neuinfo(node);
					},
					'load' : function(node) {
						if (!node.isRoot) {
							var removeNodeArr = [];

							for (var j = 0; j < node.childNodes.length; j++) {
								if (node.childNodes[j].attributes.type == 'user'
										&& (node.childNodes[j].attributes.rating != 1 && node.childNodes[j].attributes.rating != 2)) {
									removeNodeArr.push(node.childNodes[j]);
								}
							}

							if (removeNodeArr.length > 0) {
								removeNodeDecide(removeNodeArr);
							}
						}

					}
				}
			}), {
				region : 'center',
				layout : 'column',
				border : false,
				autoScroll : true,
				title : '月考勤统计',
				html : '<iframe id="frm" width="100%" height="99%" frameborder="0" src="'
						+ context + '/system/blank.jsp"></iframe>'
			}]

		})]
	});

	//Ext.getCmp('treePanel').getRootNode().expand(false);

	Ext.getCmp('treePanel').expandPath('/-1/' + groupId, '', function(a, b) {
				if (b.childNodes.length > 0) {
					b.childNodes[0].expand();
				}
			});
}

/**
 * 决定删除的节点列表
 * 
 * @param {}
 *            arr
 */
function removeNodeDecide(arr) {
	for (var i = 0; i < arr.length; i++) {
		arr[i].remove();
	}
}

/**
 * 新建内容信息
 * 
 * @param {}
 *            id
 */
function neuinfo(node) {
	if (node.attributes.type == 'user') {
		
	} else if (node.attributes.type == 'group' && node.attributes.rating == 1) {
		var url = context
				+ '/app/kqstat.do?method=monthstat&groupId='
				+ node.attributes.realid;
		if (Ext.get('frm')) {
			Ext.get('frm').dom.src = url;
		}
	}
}

function InitFormControlLocation() {
	parentTarget = document.forms[0];
	for (i = document.body.childNodes.length - 1; i > -1; i--) {
		tag = document.body.childNodes[i].tagName;
		if (tag.toUpperCase() != 'FORM') {
			obj = document.body.removeChild(document.body.childNodes[i]);
			parentTarget.insertBefore(obj, parentTarget.firstChild);
		}
	}
}